import { _detail } from '../../common/api/guest'
import { formatDate } from '../../utils/util'
const computedBehavior = require('miniprogram-computed')
const app = getApp()
Component({
  behaviors: [computedBehavior],
  data: {
    id: '',
    detail: null
  },
  computed: {
    progress () {
      return this.data.detail ? this.data.detail.CustomerLog.map(item => {
        item.AddTime = formatDate(new Date(item.AddTime), 'yyyy-MM-dd hh:mm')
        return item
      }) : []
    }
  },
  methods: {
    getDetail() {
      app.loading('加载中')
      _detail(this.data.id).then(res => {
        wx.hideLoading()
        if (res.data.IsSuccess) {
          let detail = res.data.Data
          detail.AddTime = formatDate(new Date(detail.AddTime), 'yyyy-MM-dd hh:mm')
          this.setData({
            detail
          })
        } else {
          wx.showModal({
            title: '对不起',
            content: res.data.Msg,
            showCancel: false
          })
        }
      }).catch(err => {
        console.log(err)
        wx.showModal({
          title: '对不起',
          content: '请求失败，请稍后再试',
          showCancel: false
        })
      })
    },
    onLoad(options) {
      this.data.id = options.id
      this.getDetail()
    },
    onReady() { },
    onShow() { },
    onShareAppMessage() {
      return app.shareInfo
    }
  }
})